package com.cd.blog.controller;

import com.cd.blog.mapper.ArticleMapper;
import com.cd.blog.pojo.Article;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


import java.util.List;

@Controller
public class ArticleController {

    @Autowired
    ArticleMapper articleMapper;

    @RequestMapping("/toIndexPage")
    public String toIndexPage(Model model, @RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "1") Integer size) {
        PageHelper.startPage(page, size);
        List<Article> all = articleMapper.getAll();
        PageInfo<Article> articlePageInfo = new PageInfo<>(all);
        model.addAttribute("articlePageInfo", articlePageInfo);
        List<Article> articleList = articlePageInfo.getList();
        model.addAttribute("articleList", articleList);
        return "index";
    }

}
